#include /* CapitiveSense Library Demo Sketch Paul Badger 2008 Uses a high value resistor e.g. 10M between send pin and receive pin Resistor effects sensitivity, experiment with values, 50K - 50M. Larger resistor values yield larger sensor values. Receive pin is the sensor pin - try different amounts of foil/metal on this pin */ int servo = 5; int angle; int pwm; CapacitiveSensor cs_4_2 = CapacitiveSensor(2, 4); // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired void setup() { cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example Serial.begin(9600); pinMode(15, OUTPUT); pinMode(servo, OUTPUT); } void loop() { long start = millis(); long total1 = cs_4_2.capacitiveSensor(30); Serial.print(millis() - start); // check on performance in milliseconds Serial.print("\t"); // tab character for debug windown spacing Serial.print(total1); // print sensor output 1 Serial.println("\t"); if (total1 > 1000) { for (angle = 140; angle >= 0; angle -= 5) servoPulse(servo, angle); for (angle = 0; angle <= 140; angle += 5) servoPulse(servo, angle); } } void servoPulse (int servo, int angle) { pwm = (angle * 11) + 500; digitalWrite(servo, HIGH); delayMicroseconds(pwm); digitalWrite(servo, LOW); delay(50); }